package com.hhoss.util.token;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

public class TokenUtil {
	private static final List<String> KEYS_DENY = Arrays.asList(new String[]{"0","n","no","f","false","off","deny","disable","disabled"});
	private static final List<String> KEYS_TRUE = Arrays.asList(new String[]{"1","y","yes","t","true","on","allow","enable","enabled"});

	  private TokenUtil() {
	    // Prevent Instantiation
	  }

	  public static String parse(String string, Map<?,?> variables) {
		if(string==null){return null;}
	    TokenParser parser = new TokenParser("${", "}",  TokenProvider.from("finale", variables));
	    return parser.parse(string);
	  }
		
		/**
		 * @param obj
		 * @return true if obj.toString.lower=={"-1","0","n","no","f","false","off","deny","disable","disabled"};
		 */
		public static boolean isDeny(Object obj){
			return KEYS_DENY.contains(String.valueOf(obj).toLowerCase());
		}		
		
		/**
		 * @param obj
		 * @return true if obj.toString.lower=={"1","y","yes","t","true","on","allow","enable","enabled"});
		 */
		public static boolean isTrue(Object obj){
			return KEYS_TRUE.contains(String.valueOf(obj).toLowerCase());
		}
		
		/*
		public static boolean isFalse(Object obj){
			if(obj==null){return false;}
			Boolean b = Boolean.TRUE;
			if(obj instanceof Boolean){
				b = BooleanUtils.toBooleanObject((Boolean)obj);
			}else if(obj instanceof Number){
				b = BooleanUtils.toBooleanObject(((Number)obj).intValue());
			}else if(obj instanceof String){
				b = BooleanUtils.toBooleanObject((String)obj);
			}
			
			return BooleanUtils.isFalse(b);
		}
		*/

}
